Passed
Push — master ( 5f67fe...8bce0b )
by Jesús
02:16
created

display.ts ➔ updateBinaryDisplay   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import { state } from '../../bip39';
2
import { elements } from '../../bip39';
3
import { getAllDisplayData } from '../application/displayService';
4
5
export function updateDisplay(): void {
6
  const displayData = getAllDisplayData(state.boxes);
7
  
8
  updateBoxStates(displayData.boxes);
9
  updateBinaryDisplay(displayData.binary);
10
  updateWordDisplay(displayData.word);
11
  syncWordInputFromBoxes();
12
}
13
14
function syncWordInputFromBoxes(): void {
15
  // Import dynamically to avoid circular dependency
16
  import('../../wordInput/infrastructure/wordInput').then(({ syncWordInputFromState }) => {
17
    syncWordInputFromState();
18
  });
19
}
20
21
function updateBoxStates(boxesData: Array<{ isActive: boolean; isDisabled: boolean; ariaPressed: string }>): void {
22
  const boxElements = elements.grid.querySelectorAll('.box');
23
24
  boxElements.forEach((box, index) => {
25
    const htmlBox = box as HTMLButtonElement;
26
    const data = boxesData[index];
27
28
    // Update active state
29
    htmlBox.classList.toggle('active', data.isActive);
30
    htmlBox.setAttribute('aria-pressed', data.ariaPressed);
31
32
    // Update disabled state
33
    htmlBox.classList.toggle('disabled', data.isDisabled);
34
    htmlBox.dataset.isDisabled = data.isDisabled.toString();
35
    htmlBox.setAttribute('aria-disabled', data.isDisabled.toString());
36
  });
37
}
38
39
function updateBinaryDisplay(binaryData: { binaryString: string }): void {
40
  elements.binary.textContent = binaryData.binaryString;
41
}
42
43
function updateWordDisplay(wordData: { indexText: string; announcement: string }): void {
44
  elements.index.textContent = wordData.indexText;
45
  announceToScreenReader(wordData.announcement);
46
}
47
48
function announceToScreenReader(message: string): void {
49
  const announcer = document.getElementById('sr-announcements');
50
  if (announcer) {
51
    announcer.textContent = message;
52
    // Clear after a short delay to allow for new announcements
53
    setTimeout(() => {
54
      announcer.textContent = '';
55
    }, 1000);
56
  }
57
}
58